package view;

import model.DownEvent;
import model.Event;
import model.EventVisitor;
import model.Observer;
import model.Counter;
import model.ResetEvent;
import model.UpEvent;

@SuppressWarnings("serial")
public class CounterObserver extends View implements Observer {
	
	public static CounterObserver createCounterObserver(Counter counter){
		return new CounterObserver(counter);
	}
	
	private final Counter counter;
	
	private CounterObserver(Counter counter){
		this.counter = counter;
	}
	private Counter getCounter() {
		return this.counter;
	}
	private void refresh(){
		super.refreshView(this.getCounter().getCurrentValue());
	}
	protected void deregister() {
		this.getCounter().deregister(this);
	}
	protected void register() {
		this.getCounter().register(this);
	}
	protected void down() {
		this.counter.down();
		this.refresh();
	}
	protected void up() {
		this.counter.up();
		this.refresh();
	}
	protected void reset() {
		this.counter.reset();
		this.refresh();
	}
	@Override
	public void update(Event event) {
		event.accept(new EventVisitor() {
			public void handleUpEvent(UpEvent upEvent) {
			}
			public void handleResetEvent(ResetEvent resetEvent) {
			}
			public void handleDownEvent(DownEvent downEvent) {
			}
		});
	}
}
